import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: '主页',
      // component: () => import('@/views/dashboard/index'),
      component: resolve => require(['../views/dashboard/dashboard.vue'], resolve),
      meta: { title: '主页', icon: 'dashboard' }
    }]
  },
  {
    path: '/planManage',
    component: Layout,
    redirect: '/planManage/template',
    name: '计划管理',
    meta: { title: '计划管理', icon: 'example' },
    children: [
      {
        path: 'jibenxinxi',
        name: '项目录入',
        // component: () => import('@/views/assetBusiness/registration'),
        component: resolve => require(['../views/planManage/jibenxinxi/jibenxinxi.vue'], resolve),
        meta: { title: '项目录入', icon: 'table' }
      },
      {
        path: 'template',
        name: '项目模板管理',
        // component: () => import('@/views/assetBusiness/registration'),
        component: resolve => require(['../views/planManage/template/template.vue'], resolve),
        meta: { title: '项目模板管理', icon: 'table' }
      },
      {
        path: 'changePlan',
        name: '计划变更',
        // component: () => import('@/views/assetBusiness/review'),
        component: resolve => require(['../views/planManage/changePlan/changePlan.vue'], resolve),
        meta: { title: '计划变更', icon: 'tree' }
      },
      {
        path: 'contract',
        name: ' 项目责任人变更',
        // component: () => import('@/views/assetBusiness/registration'),
        component: resolve => require(['../views/planManage/changePerson/changePerson.vue'], resolve),
        meta: { title: ' 项目负责人变更', icon: 'table' }
      },
      {
        path: 'changePersonDetail',
        name: '[原型]责任人变更详情',
        component: resolve => require(['../views/prototype/changePersonDetail.vue'], resolve),
        meta: { title: '[原型]责任人变更详情', icon: 'tree' }
      }
    ]
  },
  {
    path: '/update',
    component: Layout,
    redirect: '/update/project',
    name: '进度管理',
    meta: { title: '进度管理', icon: 'example' },
    children: [
      {
        path: 'project',
        name: '更新项目进展',
        // component: () => import('@/views/assetBusiness/registration'),
        component: resolve => require(['../views/update/project/project.vue'], resolve),
        meta: { title: '更新项目进展', icon: 'table' }
      },
      {
        path: 'overdue',
        name: '问题上报',
        // component: () => import('@/views/assetBusiness/registration'),
        component: resolve => require(['../views/update/overdue/overdue.vue'], resolve),
        meta: { title: '问题上报', icon: 'table' },
      },
      // {
      //   path: 'finance',
      //   name: '更新资金状况',
      //   // component: () => import('@/views/assetBusiness/review'),
      //   component: resolve => require(['../views/update/finance/finance.vue'], resolve),
      //   meta: { title: '更新资金状况', icon: 'tree' }
      // },
      {
        path: 'picture',
        name: '提交现场形象照',
        // component: () => import('@/views/assetBusiness/review'),
        component: resolve => require(['../views/update/picture/picture.vue'], resolve),
        meta: { title: '提交现场形象照', icon: 'table' }
      },
      {
        path: 'problemDetail',
        name: '[原型]问题详情',
        component: resolve => require(['../views/prototype/problemDetail.vue'], resolve),
        meta: { title: '[原型]问题详情', icon: 'tree' }
      }
    ]
  },
  {
    path: '/money',
    component: Layout,
    redirect: '/money/contract',
    name: '资金管理',
    meta: { title: '资金管理', icon: 'example' },
    children: [
      {
        path: 'contract',
        name: '付款合同信息上报',
        // component: () => import('@/views/assetBusiness/registration'),
        component: resolve => require(['../views/money/contract/contract.vue'], resolve),
        meta: { title: '付款合同信息上报', icon: 'table' }
      },
      {
        path: 'finance',
        name: ' 更新资金状况',
        // component: () => import('@/views/assetBusiness/registration'),
        component: resolve => require(['../views/money/finance/finance.vue'], resolve),
        meta: { title: ' 更新资金状况', icon: 'table' }
      },
      {
        path: 'moneyList',
        name: '[原型]资金流动列表',
        // component: () => import('@/views/assetBusiness/registration'),
        component: resolve => require(['../views/prototype/moneyList.vue'], resolve),
        meta: { title: '[原型]资金流动列表', icon: 'table' }
      }
    ]
  },
  {
    path: '/queryDisplay',
    component: Layout,
    redirect: '/queryDisplay/accountInquiry',
    name: '查询',
    meta: { title: '查询', icon: 'example' },
    children: [
      {
        path: 'accountInquiry',
        name: '项目基本信息',
        component: resolve => require(['../views/queryDisplay/accountInquiry/accountInquiry.vue'], resolve),
        meta: { title: '项目基本信息', icon: 'table' }
      },
      {
        path: 'chartDisplay',
        name: '项目进度',
        component: resolve => require(['../views/queryDisplay/chartDisplay/chartDisplay.vue'], resolve),
        meta: { title: '项目进度', icon: 'table' }
      },
      {
        path: 'inventory',
        name: '项目资金情况查询',
        component: resolve => require(['../views/queryDisplay/inventory/inventory.vue'], resolve),
        meta: { title: '项目资金情况查询', icon: 'table' }
      },
      {
        path: 'history',
        name: '历史记录',
        component: resolve => require(['../views/queryDisplay/history/history.vue'], resolve),
        meta: { title: '历史记录', icon: 'table' }
      }
    ]
  },
  {
    path: '/report',
    component: Layout,
    redirect: '/report/planReport',
    name: '报表与可视化',
    meta: { title: '报表与可视化', icon: 'example' },
    children: [
      {
        path: 'planReport',
        name: '资金汇总表',
        component: resolve => require(['../views/report/planReport/planReport.vue'], resolve),
        meta: { title: '资金汇总表', icon: 'table' }
      },
      {
        path: 'gatherReport',
        name: '项目汇总表',
        component: resolve => require(['../views/report/gatherReport/gatherReport.vue'], resolve),
        meta: { title: '项目汇总表', icon: 'table' }
      },
      {
        path: 'visualReport',
        name: '可视化统计',
        component: resolve => require(['../views/report/visualReport/visualReport.vue'], resolve),
        meta: { title: '可视化统计', icon: 'table' }
      }
    ]
  },
  {
    path: '/management',
    component: Layout,
    redirect: '/management/personalSettings',
    name: '系统管理',
    meta: { title: '系统管理', icon: 'example' },
    children: [
      {
        path: 'personalSettings',
        name: '用户管理',
        component: resolve => require(['../views/management/personalSettings/personalSettings.vue'], resolve),
        meta: { title: '用户管理', icon: 'table' }
      },
      {
        path: 'userPermissionSettings',
        name: ' 角色管理',
        component: resolve => require(['../views/management/userPermissionSettings/userPermissionSettings.vue'], resolve),
        meta: { title: ' 角色管理', icon: 'table' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true },
  {
    path: '/demo',
    component: Layout,
    redirect: '/demo',
    children: [{
      path: 'demo',
      name: '演示',
      component: resolve => require(['../views/table/index.vue'], resolve),
      meta: { title: '演示', icon: 'table' }
    }]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/homepage',
    children: [{
      path: 'homepage',
      name: 'demo主页',
      // component: () => import('@/views/dashboard/index'),
      component: resolve => require(['../views/homepage/homepage.vue'], resolve),
      meta: { title: 'demo主页', icon: 'dashboard' }
    }]
  },
  {
    path: '/planManage_demo',
    component: Layout,
    redirect: '/planManage_demo/template',
    name: 'demo计划管理',
    meta: { title: 'demo计划管理', icon: 'example' },
    children: [
      {
        path: 'jibenxinxi',
        name: '项目录入',
        // component: () => import('@/views/assetBusiness/registration'),
        component: resolve => require(['../views/planManage_demo/jibenxinxi/jibenxinxi.vue'], resolve),
        meta: { title: '项目录入', icon: 'table' }
      },
      {
        path: 'template',
        name: '项目模板管理',
        // component: () => import('@/views/assetBusiness/registration'),
        component: resolve => require(['../views/planManage_demo/template/template.vue'], resolve),
        meta: { title: '项目模板管理', icon: 'table' }
      },
      {
        path: 'changePlan',
        name: '计划变更',
        // component: () => import('@/views/assetBusiness/review'),
        component: resolve => require(['../views/planManage_demo/changePlan/changePlan.vue'], resolve),
        meta: { title: '计划变更', icon: 'tree' }
      },
      {
        path: 'contract',
        name: ' 项目责任人变更',
        // component: () => import('@/views/assetBusiness/registration'),
        component: resolve => require(['../views/planManage_demo/changePerson/changePerson.vue'], resolve),
        meta: { title: ' 项目负责人变更', icon: 'table' }
      },
      {
        path: 'changePersonDetail',
        name: '[原型]责任人变更详情',
        component: resolve => require(['../views/prototype/changePersonDetail.vue'], resolve),
        meta: { title: '[原型]责任人变更详情', icon: 'tree' }
      }
    ]
  },
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
